﻿using System.Web.UI;
using System.Web.UI.WebControls;

using Eneta.Portal.Common.Repository;

using Microsoft.SharePoint;

namespace Eneta.Portal.Admin.Controls
{
    public class AdminBlogEntryListControl : UserControl
    {
        protected Repeater _blogEntriesRepeater;
        protected Label _noBlogsLabel;

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            var repository = new BlogRepository(SPContext.Current.Web);
            var blogs = repository.GetPendingEntries();

            _blogEntriesRepeater.Visible = false;
            _noBlogsLabel.Visible = false;

            if (blogs != null && blogs.Results.Count > 0)
            {
                _blogEntriesRepeater.DataSource = blogs.Results;
                _blogEntriesRepeater.DataBind();
                _blogEntriesRepeater.Visible = true;
            }
            else
            {
                _noBlogsLabel.Visible = true;
            }
        }
    }
}
